package com.jack.leetcode.eachproblem_2020;

import java.util.Arrays;

/**
 * Created by zhang_j on 2020/10/26
 */
public class 零钱兑换 {

    public static void main(String[] args) {
        int[] coins = {1, 2, 5};
        System.out.println(coinChange(coins, 11));
    }

    public static int coinChange(int[] coins, int amount) {
        if(amount == 0){
            return 0;
        }
        int n = coins.length;
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, amount + 1);
        dp[0] = 0;
        for(int i = 1;i <= amount;i++){
            for(int j = 0;j < coins.length;j++){
                if(coins[j] <= i){
                    dp[i] = Math.min(dp[i], dp[i - coins[j]]) + 1;
                }
            }
        }
        return dp[amount] > amount ? -1 : dp[amount];
    }

}
